package org.jivesoftware.smack.packet;

import org.jivesoftware.smack.util.StringUtils;

public class Presence extends Packet
{
  private String language;
  private Mode mode;
  private int priority;
  private String status;
  private Type type = Type.available;

  public Presence(Type paramType)
  {
    this.status = null;
    this.priority = -2147483648;
    this.mode = null;
    setType(paramType);
  }

  public Presence(Type paramType, String paramString, int paramInt, Mode paramMode)
  {
    this.status = null;
    this.priority = -2147483648;
    this.mode = null;
    setType(paramType);
    setStatus(paramString);
    setPriority(paramInt);
    setMode(paramMode);
  }

  private String getLanguage()
  {
    return this.language;
  }

  public Mode getMode()
  {
    return this.mode;
  }

  public int getPriority()
  {
    return this.priority;
  }

  public String getStatus()
  {
    return this.status;
  }

  public Type getType()
  {
    return this.type;
  }

  public boolean isAvailable()
  {
    int i;
    if (this.type == Type.available)
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isAway()
  {
    int i;
    if ((this.type == Type.available) && (((this.mode == Mode.away) || (this.mode == Mode.xa) || (this.mode == Mode.dnd))))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public void setLanguage(String paramString)
  {
    this.language = paramString;
  }

  public void setMode(Mode paramMode)
  {
    this.mode = paramMode;
  }

  public void setPriority(int paramInt)
  {
    if ((paramInt < -128) || (paramInt > 128))
      throw new IllegalArgumentException("Priority value " + paramInt + " is not valid. Valid range is -128 through 128.");
    this.priority = paramInt;
  }

  public void setStatus(String paramString)
  {
    this.status = paramString;
  }

  public void setType(Type paramType)
  {
    if (paramType == null)
      throw new NullPointerException("Type cannot be null");
    this.type = paramType;
  }

  public String toString()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append(this.type);
    if (this.mode != null)
      localStringBuilder.append(": ").append(this.mode);
    if (getStatus() != null)
      localStringBuilder.append(" (").append(getStatus()).append(")");
    return localStringBuilder.toString();
  }

  public String toXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<presence");
    if (getXmlns() != null)
      localStringBuilder.append(" xmlns=\"").append(getXmlns()).append("\"");
    if (this.language != null)
      localStringBuilder.append(" xml:lang=\"").append(getLanguage()).append("\"");
    if (getPacketID() != null)
      localStringBuilder.append(" id=\"").append(getPacketID()).append("\"");
    if (getTo() != null)
      localStringBuilder.append(" to=\"").append(StringUtils.escapeForXML(getTo())).append("\"");
    if (getFrom() != null)
      localStringBuilder.append(" from=\"").append(StringUtils.escapeForXML(getFrom())).append("\"");
    if (this.type != Type.available)
      localStringBuilder.append(" type=\"").append(this.type).append("\"");
    localStringBuilder.append(">");
    if (this.status != null)
      localStringBuilder.append("<status>").append(StringUtils.escapeForXML(this.status)).append("</status>");
    if (this.priority != -2147483648)
      localStringBuilder.append("<priority>").append(this.priority).append("</priority>");
    if ((this.mode != null) && (this.mode != Mode.available))
      localStringBuilder.append("<show>").append(this.mode).append("</show>");
    localStringBuilder.append(getExtensionsXML());
    XMPPError localXMPPError = getError();
    if (localXMPPError != null)
      localStringBuilder.append(localXMPPError.toXML());
    localStringBuilder.append("</presence>");
    return localStringBuilder.toString();
  }

  public static enum Mode
  {
    static
    {
      available = new Mode("available", 1);
      away = new Mode("away", 2);
      xa = new Mode("xa", 3);
      dnd = new Mode("dnd", 4);
      Mode[] arrayOfMode = new Mode[5];
      arrayOfMode[0] = chat;
      arrayOfMode[1] = available;
      arrayOfMode[2] = away;
      arrayOfMode[3] = xa;
      arrayOfMode[4] = dnd;
      ENUM$VALUES = arrayOfMode;
    }
  }

  public static enum Type
  {
    static
    {
      subscribe = new Type("subscribe", 2);
      subscribed = new Type("subscribed", 3);
      unsubscribe = new Type("unsubscribe", 4);
      unsubscribed = new Type("unsubscribed", 5);
      error = new Type("error", 6);
      Type[] arrayOfType = new Type[7];
      arrayOfType[0] = available;
      arrayOfType[1] = unavailable;
      arrayOfType[2] = subscribe;
      arrayOfType[3] = subscribed;
      arrayOfType[4] = unsubscribe;
      arrayOfType[5] = unsubscribed;
      arrayOfType[6] = error;
      ENUM$VALUES = arrayOfType;
    }
  }
}